<template>
  <el-card>
    <div class="car">
      <div class="search">
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item label="年份">
            <el-select v-model="formInline.region" placeholder="年份">
              <el-option label="2021" value="2021"></el-option>
              <el-option label="2020" value="2020"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        :cell-style="cellStyle"
        :header-cell-style="rowClass"
        stripe
        :row-style="{ height: '60px', padding: '0 0' }"
      >
        <el-table-column prop="name" label="人员" width="110" align="center">
        </el-table-column>
        <el-table-column prop="one" label="一月"> </el-table-column>
        <el-table-column prop="two" label="二月"> </el-table-column>
        <el-table-column prop="three" label="三月"> </el-table-column>
        <el-table-column prop="four" label="四月"> </el-table-column>
        <el-table-column prop="five" label="五月"> </el-table-column>
        <el-table-column prop="six" label="六月"> </el-table-column>
        <el-table-column prop="seven" label="七月"> </el-table-column>
        <el-table-column prop="eight" label="八月"> </el-table-column>
        <el-table-column prop="nine" label="九月"> </el-table-column>
        <el-table-column prop="ten" label="十月"> </el-table-column>
        <el-table-column prop="eleven" label="十一月"> </el-table-column>
        <el-table-column prop="twotle" label="十二月"> </el-table-column>
        <el-table-column prop="twotle" label="合计"> </el-table-column>
      </el-table>
      <div class="block" style="float: right">
        <el-pagination
          layout="prev, pager, next"
          :total="pageNum"
          :page-size="pageSize"
          @current-change="pageChange"
        >
        </el-pagination>
      </div>
    </div>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      data: [],

      formInline: {
        region: '2021'
      },
      page: 1,
      pageSize: 5,
      pageNum: 5
    };
  },
  methods: {
    cellStyle(row, column, rowIndex, columnIndex) {
      return 'text-align:center;';
    },
    rowClass(row, rowIndex) {
      return 'text-align:center;';
    },
    onSubmit() {
      console.log('submit!');
    },
    pageChange(e) {
      console.log(e);
      this.page = e;
    },
    Render_date() {
      this.axios({
        url: 'http://localhost:8080/nan/selectAllPeople',
        params: {
          oyear: this.formInline.region
        }
      }).then(res => {
        if (res.data.code === 200) {
          this.data = res.data.data.list;
          // console.log(this.data);
        }
      });
    }
  },
  computed: {
    tableData() {
      // 0-4   page   pagenum   pagesize
      // 5-9
      return this.data.slice(
        (this.page - 1) * this.pageSize,
        this.page * this.pageSize
      );
    }
  },
  watch: {
    'formInline.region': 'Render_date',
    'deep': true
  },
  mounted() {
    this.axios({
      url: 'http://localhost:8080/nan/selectAllPeople',
      params: {
        oyear: this.formInline.region
      }
    }).then(res => {
      if (res.data.code === 200) {
        this.data = res.data.data.list;

        // console.log(this.data);
      }
    });
  }
};
</script>

<style></style>
